package com.hysf.ioc.pro3_ioc_componentscan;

import com.hysf.ioc.pro4_ioc_factorybean.FruitFactoryBean;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Arrays;

public class AppTest {
	public static void main(String[] args) {
		ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
//		Arrays.stream(context.getBeanDefinitionNames()).forEach(System.out::println);
		
//		ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) context.getAutowireCapableBeanFactory();
//		DefaultSingletonBeanRegistry registry = (DefaultSingletonBeanRegistry) beanFactory;
//		// 获取所有单例 Bean 的名称
//		String[] singletonNames = registry.getSingletonNames();
//
//		System.out.println("单例 Bean 数量: " + singletonNames.length);
//		for (String name : singletonNames) {
//			System.out.println("Bean 名称: " + name + ", 类型: " + registry.getSingleton(name).getClass().getName());
//		}
		Account account = context.getBean(Account.class);
		System.out.println(account);
//		AccountDao accountDao = context.getBean(AccountDao.class);
//		AccountService accountService = context.getBean(AccountService.class);
//		Account account = context.getBean(Account.class);
//		Account account2 = context.getBean(Account.class);
////		Person person = context.getBean(Person.class);
//		System.out.println("account == account2:"+(account == account2));
//
//		String[] beanNames = context.getBeanDefinitionNames();
//		for (String beanName : beanNames) {
//			System.out.println(beanName);
//		}
	}
}
